import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex'

export interface State {
  count: number,
  collapse: boolean
}
export const key: InjectionKey<Store<State>> = Symbol()

export const store = createStore<State>({
  state: {
    count: 0,
    collapse: false
  },
  mutations: {
    //state继承State类型 里面就是 state的所有数据类型
    setCount: (state: State, count: number) => {
      state.count = count
    },
    setCollopse: (state: State, collapse: boolean) => {
      state.collapse = collapse
    }
  },
  getters: {
    //定义数据类型
    getCount: (state: State) => { return state.count },
    getCollapse: (state: State) => {
      return state.collapse
    }
  }
})

export function useStore() {
  return baseUseStore(key)
}
export default store